package com.niiwoo.civet.trade.dao.mapper;

import com.niiwoo.civet.trade.dao.entity.ProjectInvestorPlan;
import com.niiwoo.civet.trade.dto.InvestCurrentPeriodDTO;
import com.niiwoo.civet.trade.dto.ProjectInvestorPlanAmountSumDTO;
import com.niiwoo.civet.trade.dto.ReceivedInterestDTO;
import com.niiwoo.civet.trade.dto.invest.*;
import com.niiwoo.civet.trade.dto.request.myloan.MyloanRequestDTO;
import com.niiwoo.civet.trade.dto.response.UserInvestDueInDTO;
import com.niiwoo.civet.trade.dto.response.myloan.BackToArticleByDayResponseDTO;
import com.niiwoo.civet.trade.dto.response.myloan.BackToArticleByMonResponseDTO;
import com.niiwoo.civet.trade.dto.response.myloan.InvestorPlanDTO;
import com.niiwoo.civet.trade.dto.response.myloan.inner.BackToArticleDetails;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface  ProjectInvestorPlanMapperExt extends ProjectInvestorPlanMapper {
   /**
     * 查询当期待还回款计划
     * @param projectId
     * @param period
     * @return
     */
    List<ProjectInvestorPlan> listProjectPeriodInvestorPlan(@Param("projectId")Long projectId, @Param("period")Integer period);

    /**
     * 根据标的查询所有待还回款计划
     * @param projectId
     * @return
     */
    List<ProjectInvestorPlan> listNotReceivedInvestorPlanByProjectId(@Param("projectId")Long projectId);

    /**
     * 根据回款日期查询待还回款计划
     * @param projectId
     * @param receivedDate
     * @return
     */
    List<ProjectInvestorPlan> listProjectPeriodInvestorPlanReceiveDate(@Param("projectId")Long projectId, @Param("receivedDate")Date receivedDate);

	Integer listBackToArticleDayCount(@Param("userId") String userId);

    /**
     * 回款计划-按日查看
     */
    List<BackToArticleByDayResponseDTO> listBackToArticleDayByPage(@Param("userId") String userId, @Param("page") MyloanRequestDTO page);
    
    Integer listBackToArticleByDayCount(@Param("userId") String userId, @Param("receivedDate") Date receivedDate);
    
    List<InvestorPlanDTO> listBackToArticleByDayAndPage(@Param("page") MyloanRequestDTO page, @Param("receivedDate") Date receivedDate);

    /**
     * 回款计划-按月查看
     */
    List<BackToArticleByMonResponseDTO> listBackToArticleByMonth(@Param("userId") String userId, @Param("page") MyloanRequestDTO page);

    Integer listBackToArticleByMonthCount(@Param("userId") String userId);

    /**
     * 查询用户回款计划
     * @param projectId
     * @param userId
     * @return
     */
    List<ProjectInvestorPlan> listProjectInvestorPlan(@Param("projectId") Long projectId, @Param("userId") String userId);

    List<ProjectInvestorPlan> listProjectInvestorPlanNotReceived(@Param("investOrderId") Long investOrderId, @Param("projectId") Long projectId);

    List<ProjectInvestorPlan> listProjectInvestorPlansNotReceived(@Param("list") List<Long> investOrderIds, @Param("projectId") Long projectId);

    /**
     * 查询已回款金额
     * 覃江
     * @param orderId 投资订单id
     * @param projectId 投资项目id
     * @param userId 投资用户id
     * @return
     */
    BigDecimal getInvestOrderBackedAmount(@Param("orderId") Long orderId, @Param("projectId") Long projectId, @Param("userId") String userId);

    /**
     * 查询订单已经回款期数
     * 覃江
     * @param orderId 投资订单id
     * @param projectId 投资项目id
     * @param userId 投资用户id
     * @return
     */
    int getInvestOrderBackedPeriod(@Param("orderId") Long orderId, @Param("projectId") Long projectId, @Param("userId") String userId);

    /**
     * 查询天标汇款计划
     * @param orderId 投资订单Id
     * @param projectId 投资项目Id
     * @param userId 投资用户id
     * @return
     */
    List<ProjectInvestorPlan> getInvestInvestorPlan(@Param("orderId") Long orderId, @Param("projectId") Long projectId, @Param("userId") String userId);

    int updateByPrimaryKeyCallBackSelective(ProjectInvestorPlan record);

    /**
     * 债权结清在3-30号之后的也可以
     *
     * @param projectId
     * @return
     */
    String selectFirstInvestUserId(@Param("projectId") Long projectId);

    /**
     * 债权结清在3-30号之后的也可以
     *
     * @param projectId
     * @return
     */
    String selectFirstInvestUserIdOverTime(@Param("projectId") Long projectId);

	List<ProjectInvestorPlan> listByInvestOrder(@Param("investOrderId") Long investOrderId);

    List<ProjectInvestorPlan> listInvestPlansByInvestOrderId(@Param("investOrderId") Long investOrderId,@Param("projectId") Long projectId);

    /**
     * 查询标的投资订单ID
     * @param projectId
     * @return
     */
    List<Long> selectProjectInvestOrderId(Long projectId);

    /**
     * 查询放款生成的未收款的回款计划
     * @param projectId
     * @return
     */
    List<ProjectInvestorPlan> selectNotReceived(Long projectId);

    /**
     * 根据用户id集合查询用户待收
     * @param userIdList
     * @return
     */
    List<UserInvestDueInDTO> selectUserInvestDueInGroupByUserIds(@Param("userIdList") List<String> userIdList);

    List<ProjectInvestorPlanAmountSumDTO> sumProjectInvestorPlanAmountByProjectIdAndUserId(@Param("projectId") Long projectId);
    
    List<ProjectInvestorPlan> queryProjectInvestorPlanByProjectId(@Param("projectId")Long projectId);

	List<InvestCurrentPeriodDTO> listInvestOrderCurrentPeriod(@Param("list") List<Long> investOrderIdList);

	List<ReceivedInterestDTO> listReceivedInterestGroupByInvestOrderId(@Param("list") List<Long> backedInvestOrderList);

    /**
     * 获取投资人的待收本金
     * @param userId
     * @return
     */
	BigDecimal getDueInCorpusByUserId(@Param("userId") String userId);

    List<ProjectInvestorPlan> selectNeedReceiveList(@Param("projectId") Long projectId, @Param("compareDate") Date compareDate);

    ProjectInvestorPlan getRelationFirst(@Param("projectId") Long projectId);

    ProjectInvestorPlan getRelationSecond(@Param("projectId") Long projectId);

    List<ProjectInvestorPlan> selectListByProjectIdAndPeriodList(@Param("projectId") Long projectId, @Param("list") List<Integer> periodList);

    /**
     * 根据投资订单ID统计已回款
     *
     * @param investOrderId
     * @return
     */
    ProjectInvestorPlanAmountSumDTO sumInvestorPlanAmountByInvestOrderId(@Param("investOrderId") Long investOrderId);

    Map<String,BigDecimal> sumCurrentDateForGuaranteeTotal(@Param("compareDate")Date compareDate,@Param("isOld")String isOld);

    List<Map<String,BigDecimal>> sumCurrentDateForGuaranteeTotalAll(@Param("compareDate")Date compareDate,@Param("orgId") String orgId);

    List<ProjectInvestorPlan> listInvestorPlanByProjectId(@Param("projectId") Long projectId);

    /**
     * 用户今日待回款
     * @param userId
     * @param returnDate
     * @return
     */
    List<UserTodayRelatedAmountDTO> getTodayReturnMoneyByUserId(@Param("userId")String userId, @Param("returnDate")Date returnDate);

    /**
     * 用户最近30天待回款
     * @param userId
     * @return
     */
    BigDecimal get30DayRecentlyReturnMoneyByUserId(@Param("userId")String userId);

    /**
     * 最近一期回款计划
     * @param investOrderId
     * @return
     */
    ProjectInvestorPlan getCurrentPlanByInvestOrderId(@Param("investOrderId") Long investOrderId);

    /**
     * 获取最后一期回款计划
     * @param investOrderId
     * @return
     */
    ProjectInvestorPlan getLastInvestorPlanByInvestOrderId(@Param("investOrderId") Long investOrderId);

    /**
     * 获取第一期回款计划
     * @param investOrderId
     * @return
     */
    ProjectInvestorPlan getFastInvestorPlanByInvestOrderId(@Param("investOrderId") Long investOrderId);

	ProjectInvestorPlan getCurrentPeriodInvestorPlan(@Param("investOrderId") Long investOrderId,
                                                     @Param("investUserId") String investUserId, @Param("currentPeriod") Integer currentPeriod);

	Integer getMinPeriodNotReceived(@Param("investOrderId")Long investOrderId);

    BigDecimal getRecentlyReturnMoneyByInvestOrderId(@Param("investOrderId") Long investOrderId);

    BigDecimal getRicevutoMoneyByInvestOrderId(@Param("investOrderId") Long investOrderId);

    /**
     * 查询指定期数的回款日期(包括已转让)
     * @param projectId 标的ID
     * @param currentPeriod 当前期数
     * @return ProjectInvestorPlan
     */
    Date selectProjectIdReceivedDateByPeriod(@Param("projectId") Long projectId, @Param("currentPeriod") Integer currentPeriod);

    /**
     * PC回款计划-按日查看
     */
    List<BackToArticleDetails> queryReceivableListByDate(MyloanRequestDTO requestDTO);

   /**
    * PC回款计划-按日查看总记录数
    */
   Integer queryReceivableListByDateCount(MyloanRequestDTO requestDTO);

    /**
     * 查询用户指定时间内的待回款总金额
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return BigDecimal
     */
    BigDecimal receivableAmountStatistical(@Param("userId")String userId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    List<Map<String,Object>> historyCompensatoryScanByOverdueDays(@Param("compareDate")Date date);

    Date selectMaxOverTime(@Param("investOrderId") Long investOrderId);

    /**
     * 查询用户待回款金额，根据标的ID，订单ID，投资类型分组
     * @param userId 用户ID
     * @return lsit
     */
    List<UserRelatedAmountDTO> queryUserNotReceivedAmountByUserId(@Param("userId")String userId, @Param("queryType") Byte queryType);

    /**
     * 获取用户某天所有的投资回款计划（投资日历）
     * @param userId
     * @param beginDate
     * @param endDate
     * @return
     */
	List<DayAllProjectInvestorPlanDTO> getDayAllProjectInvestorPlans(@Param("userId") String userId,
			@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);


    /**
     * 获取指定之间段内所有待收的投资回款计划（投资日历）
     * @param userId
     * @param beginDate
     * @param endDate
     * @return
     */
    List<DayAllProjectInvestorPlanDTO> getUnreceivedProjectInvestorPlans(@Param("userId") String userId,
                                                                     @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);

	/**
	 * 日统计未回款记录
	 * @param userId
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	List<InvestPlanStatDTO> findMonthEveryDayUnReceiveInvestPlans(@Param("userId") String userId,
			@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
	/**
	 * 日统计已回款记录
	 * @param userId
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	List<InvestPlanStatDTO> findMonthEveryDayReceivedInvestPlans(@Param("userId") String userId,
			@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
	/**
	 * 月统计未回款记录
	 * @param userId
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	List<InvestPlanStatDTO> findYearEveryMonthUnReceiveInvestPlans(@Param("userId") String userId,
			@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
	/**
	 * 月统计已回款记录
	 * @param userId
	 * @param beginDate
	 * @param endDate
	 * @return
	 */
	List<InvestPlanStatDTO> findYearEveryMonthReceivedInvestPlans(@Param("userId") String userId,
			@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);

	List<ProjectInvestorPlan> findAllPrizePlans(@Param("userId") String userId,
			@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);


    /**
     * 查询用户所有的智能投订单加息的标订单ID
     */
    List<Long> queryPackageAddInterestInvestOrderIdByUserId(@Param("userId")String userId);

    /**
     * 查询用户所有的智能投订单加息的标订单ID
     */
    List<ProjectInvestorPlan> queryPackageAddInterestInvestorPlanByInvestOrderIdSet(@Param("investOrderIdSet")Set<Long> investOrderIdSet, @Param("receivedDate")Date receivedDate);

    /**
     * 查询用户所有的标订单加息的标订单ID
     */
    List<Long> queryProjectAddInterestInvestOrderId(@Param("userId")String userId, @Param("queryType")Byte queryType);

    Integer getCurrentPeriodPackageReceivedProjectNumByPackageInvestOrderIdAndPeriodAndUserId(@Param("packageInvestOrderId") Long packageInvestOrderId, @Param("currentPeriod") Integer currentPeriod, @Param("userId") String userId);

    BigDecimal getCurrentPeriodPackageReceivedTotalAmountByPackageInvestOrderIdAndPeriodAndUserId(@Param("packageInvestOrderId") Long packageInvestOrderId, @Param("currentPeriod") Integer currentPeriod, @Param("userId") String userId);

    /**
     * 查询智能投订单下某个已满的标的待收本息总金额
     * @param investOrderIds 包订单ID
     * @return FullProjectDueInPrincipalAndInterestDTO
     */
    List<FullProjectDueInPrincipalAndInterestDTO> selectIntelligenceFullProjectDueInPrincipalAndInterest(@Param("investOrderIds") Set<Long> investOrderIds);

}